package com.nowcoder;


import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int cur = 0;
        int n = tickets.length;
        int ans = 0;
        while(tickets[k] != 0) {
            if(tickets[cur] == -1) {
                cur = (cur + 1) % n;
                continue;
            }
            ans++;
            tickets[cur] -= 1;
            cur = (cur + 1) % n;
        }
        return ans;
    }
    @Test
    public void test() {
        int res = timeRequiredToBuy(new int[]{5,1,1,1}, 0);
        System.out.println(res);
    }
}

// [2,3,4,7,11]
//  1 2 3 4 5
//  1 1 1 3 6
// 找到第一个小于x的数